package org.sang.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.sang.controller.form.ExamCategoryForm;
import org.sang.pojo.RespBean;
import org.sang.pojo.dto.ExamCategoryDTO;
import org.sang.service.ExamCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/exam")
@Api(value = "ExamCategoryController", tags = "面试题类目相关接口")
public class ExamCategoryController {
    @Resource
    private ExamCategoryService examCategoryService;

    @PostMapping("/category")
    @ApiOperation(value = "addExamCategory", notes = "添加面试题类目", consumes="application/json", produces = "application/json", response = RespBean.class)
    public RespBean<Integer> addExamCategory(@RequestBody ExamCategoryDTO examCategory){
        return examCategoryService.addCategory(examCategory);
    }

    @GetMapping("/categories")
    @ApiOperation(value = "getExamCategories", notes = "获取全部面试题类目", consumes="application/json", produces = "application/json", response = RespBean.class)
    public RespBean<List<ExamCategoryDTO>> getExamCategories(){
        return examCategoryService.getAllCategories();
    }

    @PostMapping("/findCategoryByCondition")
    @ApiOperation(value = "findExamCategoriesByCondition", notes = "根据条件查询面试题类目", consumes="application/json", produces = "application/json", response = RespBean.class)
    public RespBean<List<ExamCategoryDTO>> findExamCategoriesByCondition(@RequestBody ExamCategoryForm examCategoryForm){
        return examCategoryService.findExamCategoriesByCondition(examCategoryForm);
    }

    @PostMapping("/editCategory")
    public RespBean<Integer> editCategory(@RequestBody ExamCategoryDTO examCategory){
        return examCategoryService.editCategory(examCategory);
    }

    @PostMapping("/deleteCategory")
    public RespBean<Integer> deleteCategory(@RequestParam("id") Integer id){
        return examCategoryService.deleteById(id);
    }

}
